package com.projecy.system.controller;

import com.projecy.common.exception.BadRequestException;
import com.projecy.common.utils.ResultUtil;
import com.projecy.logs.annotation.Log;
import com.projecy.system.model.dto.RoleMenuDto;
import com.projecy.system.service.SysRoleMenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequiredArgsConstructor
@RequestMapping("sys")
public class SysRoleMenuController extends ResultUtil {
    @Autowired
    SysRoleMenuService roleMenuService;

    @Log("获取角色菜单")
    @GetMapping("/role/menu/list")//通过角色ID获取对应的菜单
    public ResponseEntity<Object> getMenuByRoleId(Long roleId){
        System.out.println("获取角色菜单");
        try {
            return success(true, roleMenuService.getMenuByRoleId(roleId));
        } catch (BadRequestException e) {
            e.printStackTrace();
            return fail(false, e.getMsg());
        }
    }

    @Log("授权角色菜单")
    @PostMapping("/role/menu/edit")
    public ResponseEntity<Object> editMenuRoleByRoleId(@RequestBody RoleMenuDto roleMenuDto){
        System.out.println("授权角色菜单");
        try {
            roleMenuService.editMenuRoleByRoleId(roleMenuDto);
            return success(true, "授权成功");
        } catch (BadRequestException e) {
            e.printStackTrace();
            return fail(false, e.getMsg());
        }
    }





}
